﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DAL_Support
/// </summary>
public class DAL_Support
{
    DbProvider db = new DbProvider();

    public void Support_Insert(DTO_Support obj)
    {

        string sql = string.Format("INSERT INTO [Support] VALUES ('N{0}',N'{1}',N'{2}',N'{3}',N'{4}',N'{5}')", obj.Name, obj.Tell, obj.Type, obj.Nick, obj.Order, obj.Status);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }
    public void Support_UpdateByAll(string Id, DTO_Support obj)
    {

        string sql = string.Format("UPDATE [Support] SET [Name] = '{0}',Tell = '{1}',[Type] = '{2}',[Nick] = '{3}',[Order] = {4}',[Status] = '{5} WHERE [Id] = '{6}'", obj.Name, obj.Tell, obj.Type, obj.Nick, obj.Order, obj.Status, Id);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }

    public void Support_UpdateBySet(string Id, string Set)
    {

        string sql = string.Format("UPDATE [Support] SET {0} WHERE [Id] = '{1}'", Set, Id);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }
    public void Support_Delete(string Id)
    {

        string sql = string.Format("DELETE FROM Support WHERE Id = '{0}'", Id);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }

    public DataTable Support_GetByAll(int Status)
    {
        DataTable dt = new DataTable();
        string sql = string.Format("select * from Support where [Status]= '{0}' ", Status);
        try
        {
            dt = db.ExecuteQuery(sql);

        }
        catch (Exception)
        {

            throw;
        }
        return dt;
    }
    public DataTable Support_GetByTop(int top, string where, string order)
    {
        DataTable dt = new DataTable();
        //string sql = string.Format("select top {0} * from Product where = '{1}' Support by [{2}] DESC,[Support]", top, where,Support);
        string sql = "";
        if (top <= 0)
        {
            sql += "SELECT * FROM [Support]";
        }
        else
        {
            sql += "SELECT TOP " + top + " * FROM [Support]";
        }
        if (where != "")
        {
            sql += " WHERE " + where;
        }
        if (order != "")
        {
            sql += " Order by " + order;
        }
        try
        {
            dt = db.ExecuteQuery(sql);

        }
        catch (Exception)
        {

            throw;
        }
        return dt;
    }
    public DataTable Support_GetByID(string id)
    {
        DataTable dt = new DataTable();
        string sql = string.Format("select * from Support where Id = {0}", id);
        try
        {
            dt = db.ExecuteQuery(sql);

        }
        catch (Exception)
        {

            throw;
        }
        return dt;
    }
}